﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using Entities;
using Sales.DataAccess.DO;

namespace Sales.WebAPI.Controllers
{
    public class CustomerController : ApiController
    {
        private CustomerDO CustomerDO;

        public CustomerController()
        {
            CustomerDO = new CustomerDO();
        }
        
        // GET api/values
        public IEnumerable<Customer> Get()
        {
            return CustomerDO.GetAll();
        }

        // GET api/values/5
        public Customer Get(int id)
        {
            return CustomerDO.GetSingle(cus => cus.CID == id);
        }

        // POST api/values
        public void Post(Customer customer)
        {
            CustomerDO.Add(customer);
        }

        // PUT api/values/5
        public void Put(int id, Customer customer)
        {
            customer.CID = id;
            CustomerDO.Update(customer);
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
            var customer = CustomerDO.GetSingle(cus => cus.CID == id);
            CustomerDO.Remove(customer);
        }

    }
}
